//
//  HomeViewModel.m
//  AppointmentForCar
//
//  Created by TheMacBook on 2016/11/7.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "HomeViewModel.h"
#import "PushManager.h"

@implementation HomeViewModel

- (HomeViewModel * (^)(void))getDriverHistoricalRecordWithId:(NSString *)DriverId complete:(CompleteBackCallBlock)complete
{
    [HUDManager showLoadingHUDViewWithText:kMessage_NetLoading];
    [NetWork postNetWorkWithUrl:@"driver-history-order" parame:@{@"driverId":DriverId} successBlock:^(NSDictionary *dic) {
        [HUDManager hideHUDView];
        if([dic[@"data"][@"orders"] isKindOfClass:[NSNull class]] || [dic[@"status"] integerValue] != 0)
        {
            complete(dic[@"message"]);
        }else
        {
            _dataArray = [HomeHistoryModel mj_objectArrayWithKeyValuesArray:dic[@"data"][@"orders"]];
            NSLog(@"_dataArray = %@", _dataArray);
            complete(nil);
        }
    } errorBlock:^(id error) {
        [HUDManager hideHUDView];
        complete(error);
    }];
    return ^id(){
        return self;
    };
}
- (HomeViewModel *(^)(void))getDriverBriefInformationWithId:(NSString *)driverid complete:(CompleteBackCallBlock)complete {
    [NetWork postNetWorkWithUrl:@"driver-info" parame:@{@"driverId":driverid} successBlock:^(NSDictionary *dic) {
        if([dic[@"data"][@"orders"] isKindOfClass:[NSNull class]] || [dic[@"status"] integerValue] != 0) {
            complete(dic[@"message"]);
        } else {
            _driver = [DriverModel mj_objectWithKeyValues:dic[@"data"]];
            complete(nil);
        }
    } errorBlock:^(id error) {
        complete(error);
    }];
    return ^id(){
        return self;
    };
}

- (HomeViewModel * (^)(void))grabOrderWithReservationId:(NSString *)reservationId complete:(CompleteBackCallBlock)complete {
    NSDictionary * params = @{@"reservationId":reservationId,@"driverId":_driver.driverId,@"carBrand":_driver.carModel,@"driverNickName":_driver.driverNickName,@"driverPhoneNumber":_driver.driverPhoneNumber,@"licensePlate":_driver.licensePlate};
    [NetWork postNetWorkWithUrl:@"rob-order" parame:params successBlock:^(NSDictionary *dic) {
        if(complete) {
            complete(nil);
        }
    } errorBlock:^(id error) {
        if(complete) {
            complete(error);
        }
    }];
    return ^id(){
        return self;
    };
}

- (HomeViewModel * (^)(void))driverOutCarWithdriverIdWithcomplete:(CompleteBackCallBlock)complete {
    NSDictionary * params = @{@"driverId":_driver.driverId};
    [NetWork postNetWorkWithUrl:@"driver-out-car" parame:params successBlock:^(NSDictionary *dic) {
        if([dic[@"status"] integerValue] != 0) {
            // 未登录，请重新登录 status = 5
            complete(dic[@"message"]);
        } else {
            if(complete) {
                complete(nil);
                [PushManager sharePushManager].pushSwith = YES;
            }
        }
    } errorBlock:^(id error) {
        if(complete) {
            complete(error);
        }
    }];
    return ^id(){
        return self;
    };
}

- (HomeViewModel * (^)(void))driverBackCarWithdriverIdWithcomplete:(CompleteBackCallBlock)complete {
    NSDictionary * params = @{@"driverId":_driver.driverId};
    [NetWork postNetWorkWithUrl:@"driver-back-car" parame:params successBlock:^(NSDictionary *dic) {
        if([dic[@"status"] integerValue] != 0) {
            // 未登录，请重新登录 status = 5
            complete(dic[@"message"]);
        } else {
            if(complete) {
                complete(nil);
                [PushManager sharePushManager].pushSwith = NO;
            }
        }
    } errorBlock:^(id error) {
        if(complete) {
            complete(error);
        }
    }];
    return ^id(){
        return self;
    };
}

- (HomeViewModel * (^)(void))robOrderWithReservationId:(NSString *)reservationId complete:(CompleteBackCallBlock)complete {
    NSDictionary * parame = @{@"reservationId":reservationId,@"driverId":_driver.driverId,@"carBrand":_driver.carModel?_driver.carModel:@"",@"driverNickName":_driver.driverNickName,@"driverPhoneNumber":_driver.driverPhoneNumber,@"licensePlate":_driver.licensePlate};
    [NetWork postNetWorkWithUrl:@"rob-order" parame:parame successBlock:^(NSDictionary *dic) {
        if([dic[@"status"] integerValue] != 0) {
            // 未登录，请重新登录 status = 5
            complete(dic[@"message"]);
        } else {
            if(complete) {
                complete(nil);
                [PushManager sharePushManager].pushSwith = NO;
            }
        }
    } errorBlock:^(id error) {
        if(complete) {
            complete(error);
        }
    }];
    return ^id(){
        return self;
    };
}

@end
